#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 5, maxn2 = 1e6 + 5;
int s[maxn];
bool vis[maxn2];

int main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    ios::sync_with_stdio(0);
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        for(int i = 1;i <= n;i++)  cin>>s[i];
        //bool color = 1;    //1 red    0 blue
        int ans = 0;
        for(int i = 1;i <= n;i++)
        {
            if(vis[s[i]] == 1)  continue;
            vis[s[i]] = 1;
            int cnt = 0;
            for(int j = 1;j <= n;j++)
            {
                if(s[j] == s[i])  cnt++;
            }
            ans += (cnt - 1) * s[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}
